<template>
  <div class="emoji">
    <i
      class="iconfont icon-biaoqing"
      @click.stop="isShowEmoji = !isShowEmoji"
    ></i>
    <div class="emojiList" v-show="isShowEmoji">
      <ul>
        <li
          v-for="(item, i) in emojiData"
          :key="i"
          @click.stop="clickEmoji(item)"
        >
          {{ item }}
        </li>
      </ul>
    </div>
  </div>
</template>

<script>
import emojiData from "./emojiData.js";
export default {
  props: {
    msgdata: String,
  },
  data() {
    return {
      isShowEmoji: false,
      emojiData: emojiData,
    };
  },
  methods: {
    clickEmoji(item) {
      this.$emit("addEmoji", item, this.msgdata);
      // console.log(this.msgdata);
    },
  },
  mounted() {
    document.addEventListener("click", () => {
      this.isShowEmoji = false;
    });
  },
};
</script>

<style lang="less" scoped>
.emoji {
  position: relative;
  .emojiList {
    z-index: 999;
    position: absolute;
    top: 28px;
    padding: 8px;
    background-color: #fff;
    box-shadow: 0 0 3px #ccc;
    &::before {
      content: "";
      display: block;
      position: absolute;
      top: -13px;
      left: 0;
      border: 6px solid transparent;
      border-bottom-color: #eee;
    }
    ul {
      display: flex;
      flex-wrap: wrap;
      width: 280px;
      background: #fff;
      border: 1px solid #eee;
      li {
        font-size: 16px;
        width: 28px;
        height: 28px;
        line-height: 28px;
        text-align: center;
        cursor: pointer;
        &:hover {
          background: #eee;
        }
      }
    }
  }
}
</style>

